package filter;

import servlet.IndexImgServlet;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@WebFilter(urlPatterns = "/*")
public class EncodingFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("FilterFilterFilterFilterFilterFilter initinitinitinitinit");
        Filter.super.init(filterConfig);
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        chain.doFilter(request, response);
        System.out.println("on doFilter");
        System.out.println(request.getAttribute("username"));
//        System.out.println(session.getAttribute("username"));
    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }
}
